<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>
  </head>
  <body>
    用户名：<input type="text" name="username" id="username" /> 密码：<input
      type="password"
      name="password"
      id="password"
    />
    <input type="button" value="登录" id="login" />
    <div id="box"></div>
    <script>
      $(function () {
        $('#login').click(function () {
          var username = $('#username').val()
          var password = $('#password').val()
          $.ajax({
            url: 'http://2022web/index.php',
            type: 'post',
            data: {
              username: username,
              password: password,
            },
            dataType: 'json',
            success: function (res) {
              if (res.code == 200 && res.msg == 'success') {
                alert('登录成功')
                $('#box').html(
                  '<a href="http://2022web/userinfo.php">用户详情信息</a>'
                )
              } else {
                alert('用户名或密码错误')
              }
            },
          })
        })
      })
    </script>
  </body>
</html>
